# Create your views here.
# coding=utf-8
#from django.http import HttpResponse
from models import *
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.shortcuts import RequestContext
from django.conf import settings

def Index(request):  
    if request.method == 'GET': 
        return render_to_response('index.html',context_instance=RequestContext(request))
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        users = Users.objects.filter(username=username,password=password)
        result =  len(users)
        if result>0: 
            request.session['user_session'] = username
            request.session.set_expiry(0)
            return HttpResponseRedirect('/console')
        else:
            mess =  '登录失败,用户名与密码错误'
        return render_to_response('index.html',{'message':mess},context_instance=RequestContext(request))



def Console(request):  
    return render_to_response('console.html')